package com.ling.service;

import com.ling.bean.BlogComment;
import com.ling.bean.BlogCommentExample;
import com.ling.dao.BlogCommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogCommentService {
    @Autowired
    private BlogCommentMapper blogCommentMapper;

    //根据博客id获取评论信息
    public List<BlogComment> getBlogCommentByBlogId(String blogId) {
        BlogCommentExample blogCommentExample = new BlogCommentExample();
        blogCommentExample.setOrderByClause("editTime DESC");
        blogCommentExample.createCriteria().andBlogidEqualTo(blogId);
        return blogCommentMapper.selectByExampleWithHeadImg(blogCommentExample);
    }

    //添加评论
    public void addBlogComment(BlogComment blogComment) {
        blogCommentMapper.insertSelective(blogComment);
    }

    //删除评论

    //查询指定用户收到的博客评论
    public List<BlogComment> getBlogCommentByUser(String userId) {
        BlogCommentExample blogCommentExample = new BlogCommentExample();
        blogCommentExample.setOrderByClause("editTime DESC");
        blogCommentExample.createCriteria().andTouseridEqualTo(userId);
        return blogCommentMapper.selectByExampleWithHeadImg(blogCommentExample);
    }

}
